<?php
class item_multipleeffect extends template_item
{
	var $default_name = "Multiple Name Effect";
	var $default_description = "Add an effect to your name with an addition to others.";
	
	var $allow_multiple = 1;
	
	var $item_config = array();
	
	function load_item(&$item)
	{
		parent::load_item($item);
		
		if($item['item_config'] || $item['item_id'] != 0)
		{
			$this->item_config = unserialize($item['item_config']);
		}
		else
		{
			$this->item_config['effect'] = 'bold';
			$this->item_config['add_remove'] = 'add';
		}
	}
	
	function admin_form()
	{
		$effects = array();
		$effects[] = array('bold',"Bold");
		$effects[] = array('italics',"Italics");
		$effects[] = array('color',"Font Color");
		$effects[] = array('background',"Background Color");
		$effects[] = array('dropshadow',"Drop Shadow (IE only)");
		$effects[] = array('shadow',"Shadow (IE only)");
		$effects[] = array('glow',"Glow (IE only)");
		$effects[] = array('blur',"Blur (IE only)");
		$effects[] = array('flipv',"Vertical Flip (IE only)");
		$effects[] = array('fliph',"Horizontal Flip (IE only)");
		$effects[] = array('wave',"Wave (IE only)");
		$effects[] = array('xray',"X-Ray (IE only)");
		$effects[] = array('invert',"Invert (IE only)");
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Which effect to apply?</b><br /><b>Bold</b><br /><i>Italics</i><br /><div style='color:#FF00FF;width:100%;'>Purple Font Color</div><div style='background-color:#00FFFF;width:100%;'>Teal/Aqua Background Color</div><div style='filter: dropshadow(color=#0000FF, offx=5, offy=-3, Positive=1);width:100%;'>Blue Drop Shadow</div><div style='filter: shadow(color=#FF0000, direction=45);width:100%;'>Red Shadow</div><div style='filter: glow(color=#00FF00, strength=6); width:100%'>Green Glow</div><div style='filter: blur(add=false, direction=140, strength=6); width:100%;'>Blur</div><div style='filter: flipv; width:100%;'>Vertical Flip</div><div style='filter: fliph; width:100%;'>Horizontal Flip</div><div style='filter: wave(strength=2); width:100%;'>Wave</div><div style='filter: xray; width:100%;'>X-Ray</div><div style='filter: invert; width:100%;'>Invert</div>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][effect]", $effects, $this->item_config['effect'],"size='".count($effects)."'"),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Add or remove effect to the name?</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][add_remove]", array(array('add','Add Effect'),array('remove','Remove Effect')),$this->item_config['add_remove']),
													)	);
		
		return $html;
	}
	
	function admin_save(&$item_info, $input)
	{
		$save = array();
		$save['effect'] = $input['effect'];
		$save['add_remove'] = $input['add_remove'];
		
		$item_info['item_config'] = serialize($save);
		
		if($this->ipsclass->DB->field_exists("multiple_effect", "members"))
		{
			$this->ipsclass->DB->sql_change_field("members","multiple_effect","multiple_effect","TEXT NOT NULL","''");
		}
		else
		{
			$this->ipsclass->DB->sql_add_field("members","multiple_effect","TEXT NOT NULL","''");
		}
	}
	
	function admin_remove()
	{
		if(count($this->ipsclass->market_class->item_by_folder[$this->item['filename']]) == 1)
		{
			$this->ipsclass->DB->sql_drop_field("members","multiple_effect");
		}
	}
	
	function admin_view_file_edits()
	{
		$edits = "";
		
		$edits .= $this->ipsclass->adskin->start_table("Files to edit");
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"/index.php<br />/sources/action_public/profile.php<br />/sources/action_public/topics.php<br />/sources/sql/mysql_queries.php",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("/index.php");
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 64', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>require_once KERNEL_PATH . \"class_converge.php\";\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>require_once ROOT_PATH   . \"sources/market/multiple_effects.php\";\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It will look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>require_once KERNEL_PATH . \"class_converge.php\";\nrequire_once ROOT_PATH   . \"sources/market/multiple_effects.php\";\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("/sources/action_public/profile.php");
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 3159', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>		//-----------------------------------------\n		// Online location\n		//-----------------------------------------\n		\n		\$member = \$this->personal_portal_get_user_location( \$member );\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the function",
																"view_profile()",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add before",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>		list(\$member['multiple_prefix'],\$member['multiple_suffix']) = parse_effect(\$member);\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It will look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>		list(\$member['multiple_prefix'],\$member['multiple_suffix']) = parse_effect(\$member);\n		//-----------------------------------------\n		// Online location\n		//-----------------------------------------\n		\n		\$member = \$this->personal_portal_get_user_location( \$member );\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 3948', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>    	\$info['members_display_name'] = \$member['members_display_name'];\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the function",
																"view_profile()",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>    	list(\$info['multiple_prefix'],\$info['multiple_suffix']) = parse_effect(\$member);\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It will look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>    	\$info['members_display_name'] = \$member['members_display_name'];\n    	list(\$info['multiple_prefix'],\$info['multiple_suffix']) = parse_effect(\$member);\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("/sources/action_public/topics.php");
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 915', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>			\$poster['_members_display_name'] = \"<a href='{\$this->base_url}showuser={\$poster['id']}'>{\$poster['members_display_name_short']}</a>\";\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the function",
																"parse_row( \$row = array() )",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Replace it with",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>			\$effect = parse_effect(\$poster);\n			\$poster['_members_display_name'] = \"<a href='{\$this->base_url}showuser={\$poster['id']}'>{\$effect[0]}{\$poster['_pp_online_image']}{\$poster['members_display_name_short']}{\$effect[1]}</a>\";\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("/sources/sql/mysql_queries.php");
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 167', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>				me.msnname,me.aim_name,me.icq_number,me.signature, me.website,me.yahoo,me.location, me.avatar_location, me.avatar_type, me.avatar_size, m.members_display_name</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the function",
																"topics_get_posts( \$a )",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>,m.multiple_effect</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It will look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>				me.msnname,me.aim_name,me.icq_number,me.signature, me.website,me.yahoo,me.location, me.avatar_location, me.avatar_type, me.avatar_size, m.members_display_name,m.multiple_effect</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 182', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>				me.msnname,me.aim_name,me.icq_number,me.signature, me.website,me.yahoo,me.location, me.avatar_location, me.avatar_type, me.avatar_size, m.members_display_name,</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the functions",
																"topics_get_posts_with_join( \$a )",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>m.multiple_effect,</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It should look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>				me.msnname,me.aim_name,me.icq_number,me.signature, me.website,me.yahoo,me.location, me.avatar_location, me.avatar_type, me.avatar_size, m.members_display_name,m.multiple_effect,</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		$edits .= $this->ipsclass->adskin->start_table("Templates to edit");
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																			"Profile View Skin<br />- personal_portal_main<br />- show_profile<br />Topic View Skin<br />- RenderRow",
																	)	);
		$edits .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("Topic View Skin");
		$edits .= $this->ipsclass->adskin->add_td_basic('RenderRow', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"How to get there",
																"Go click the LOOK & FEEL tab on top or <a href='".$this->ipsclass->base_url."&amp;section=lookandfeel' target='_blank'>here</a> open a new window.<br />Click Skin Manager on the left.<br />On each skin, clikc the options icon and click Edit Template HTML.<br />Click Topic View, then click RenderRow on the right side.",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>{\$author['_pp_online_image']}</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
															"Change it to",
															"<textarea rows='5' cols='50' class='multitext' style='width:98%'><!-- {\$author['_pp_online_image']} --></textarea>",
													)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("Profile View Skin");
		$edits .= $this->ipsclass->adskin->add_td_basic('personal_portal_main', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"How to get there",
																"Click Profile View on the bottom left, then click personal_portal_main on the bottom right side.",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find on the top",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'><h3 style='font-size:20px'>{\$member['members_display_name']}</h3></textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add before {\$member['members_display_name']}",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>{\$member['multiple_prefix']}</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after {\$member['members_display_name']}",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>{\$member['multiple_suffix']}</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It should look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'><h3 style='font-size:20px'>{\$member['multiple_prefix']}{\$member['members_display_name']}{\$member['multiple_suffix']}</h3></textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_basic('show_profile', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"How to get there",
																"Click show_profile on the bottom right side.",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find on the top",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'><div id=\"profilename\">{\$info['members_display_name']}</div></textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add before {\$info['members_display_name']}",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>{\$info['multiple_prefix']}</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add after {\$info['members_display_name']}",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>{\$info['multiple_suffix']}</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It should look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'><div id=\"profilename\">{\$info['multiple_prefix']}{\$info['members_display_name']}{\$info['multiple_suffix']}</div></textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		return $edits;
	}
	
	function public_use_form($inventory_ids = array())
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$hidden_fields = $this->_get_hidden_fields($inventory_ids);
		
		$this->ipsclass->member['members_display_name_short'] = $this->ipsclass->txt_truncate( $this->ipsclass->member['members_display_name'], 16 );
		
		$effect = $this->ipsclass->member['multiple_effect'] ? unserialize($this->ipsclass->member['multiple_effect']) : array();
		$effect = is_array($effect) ? $effect : array();
		
		if($this->item_config['add_remove'] == 'add')
		{
			$default = array();
			$default['color'] = isset($effect[$this->item_config['effect']]['color']) ? $effect[$this->item_config['effect']]['color'] : '#888888';
			$default['strength'] = isset($effect[$this->item_config['effect']]['strength']) ? $effect[$this->item_config['effect']]['strength'] : 0;
			$default['direction'] = isset($effect[$this->item_config['effect']]['direction']) ? $effect[$this->item_config['effect']]['direction'] : 120;
			$default['show_text'] = isset($effect[$this->item_config['effect']]['show_text']) ? ($effect[$this->item_config['effect']]['show_text'] ? 'true' : 'false') : 'false';
			$default['offx'] = isset($effect[$this->item_config['effect']]['offx']) ? $effect[$this->item_config['effect']]['offx'] : 5;
			$default['offy'] = isset($effect[$this->item_config['effect']]['offy']) ? $effect[$this->item_config['effect']]['offy'] : -3;
			$default['drop_background'] = isset($effect[$this->item_config['effect']]['drop_background']) ? ($effect[$this->item_config['effect']]['drop_background'] ? 'true' : 'false') : 'false';
			
			unset($effect[$this->item_config['effect']]);
			
			$effects = $this->parse_effect($effect);
			
			$pick_color = "";
			if(!in_array($this->item_config['effect'],array('bold','italics','blur','flipv','fliph','wave','xray','invert')))
			{
				$cmap = array();
				
				for($b = 0; $b < 16; $b++)
				{
					for($g = 0; $g < 16; $g++)
					{
						for($r = 0; $r < 16; $r++)
						{
							$cmap[floor($b/4)] .= "					<area shape='rect' coords='".($g*4+$b%4*64).",".($r*6).",".($g*4+$b%4*64+3).",".($r*6+5)."' onmouseover=\"javascript:preview_hex('#".strtoupper(($r == 0 ? "00" : dechex($r*17)).($g == 0 ? "00" : dechex($g*17)).($b == 0 ? "00" : dechex($b*17)))."')\" onclick='preview_color()'>\n";
						}
					}
				}
				
				$pick_color = <<<EOF
		<tr>
			<td class='row1' align='center' colspan='3'>
				<b>{$this->ipsclass->lang['choose_color']}</b>
			</td>
		</tr>
		<tr>
			<td class='row2' align='center' colspan='3'>
				<map name='colormap1'>
{$cmap[0]}
				</map>
				<map name='colormap2'>
{$cmap[1]}
				</map>
				<map name='colormap3'>
{$cmap[2]}
				</map>
				<map name='colormap4'>
{$cmap[3]}
				</map>
				<img usemap='#colormap1' src='{$this->ipsclass->market_class->image_url_path}/color_table-1.png' border='0' /><img usemap='#colormap2' src='{$this->ipsclass->market_class->image_url_path}/color_table-2.png' border='0' />
				<br />
				<img usemap='#colormap3' src='{$this->ipsclass->market_class->image_url_path}/color_table-3.png' border='0' /><img usemap='#colormap4' src='{$this->ipsclass->market_class->image_url_path}/color_table-4.png' border='0' />
				<br />
				{$this->ipsclass->lang['hex_code']}: <input type='text' id='preview_hex_color' value='' class='textinput' /> <input type='button' value='{$this->ipsclass->lang['preview']}' class='textinput' onclick='preview_color()' />
			</td>
		</tr>
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['color_preview']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='text' name='color' id='color' value='{$default['color']}' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			$strength = "";
			if(in_array($this->item_config['effect'],array('blur','wave','glow')))
			{
				$strength = <<<EOF
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['change_strength']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='button' value='+' onclick='change_strength(1)' class='textinput' /><input type='button' value='-' onclick='change_strength(-1)' class='textinput' />
				<input type='hidden' name='strength' id='strength' value='0' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			$direction = "";
			if(in_array($this->item_config['effect'],array('blur','shadow')))
			{
				$direction = <<<EOF
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['change_direction']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='button' value='{$this->ipsclass->lang['rotate_clockwise']}' onclick='change_direction(1)' class='textinput' />
				<br />
				<input type='button' value='{$this->ipsclass->lang['rotate_counter_clockwise']}' onclick='change_direction(-1)' class='textinput' />
				<br />
				<input type='text' id='change_direction_number' value='30' class='textinput' />&deg;
				<input type='hidden' name='direction' id='direction' value='120' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			$show_text = "";
			if($this->item_config['effect'] == 'blur')
			{
				$checked = $default['show_text'] == 'true' ? 'checked ' : '';
				$show_text = <<<EOF
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['show_unblur_text']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='checkbox' id='show_text' name='show_text' value='1' {$checked}onclick='change_text_shown()' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			$offset = "";
			if($this->item_config['effect'] == 'dropshadow')
			{
				$offset = <<<EOF
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['shadow_offect']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='button' value='&larr;' onclick='change_offset(-1,0)' class='textinput' /><input type='button' value='&uarr;' onclick='change_offset(0,-1)' class='textinput' /><input type='button' value='&darr;' onclick='change_offset(0,1)' class='textinput' /><input type='button' value='&rarr;' onclick='change_offset(1,0)' class='textinput' />
				<input type='hidden' name='x_offset' id='x_offset' value='5' class='textinput' />
				<input type='hidden' name='y_offset' id='y_offset' value='-3' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			$background = "";
			if($this->item_config['effect'] == 'dropshadow')
			{
				$checked = $default['drop_background'] == 'false' ? 'checked ' : '';
				$background = <<<EOF
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['show_dropshadow_background']}</b>
			</td>
			<td class='row1' align='left'>
				<input type='checkbox' id='drop_background' name='drop_background' value='1' {$checked}onclick='change_dropshadow_background()' class='textinput' />
			</td>
		</tr>

EOF;
			}
			
			return <<<EOF
<script type="text/javascript">
var effect = '{$this->item_config['effect']}';
var short_name = "{$this->ipsclass->member['members_display_name_short']}";
var color = '{$default['color']}';
var strength = {$default['strength']};
var direction = {$default['direction']};
var show_text = {$default['show_text']};
var offset_x = {$default['offx']};
var offset_y = {$default['offy']};
var show_drop_bg = {$default['drop_background']};
function preview_hex(val)
{
	document.getElementById('preview_hex_color').value = val;
}
function preview_color()
{
	if(document.getElementById('preview_hex_color').value == "")
	{
		return;
	}
	
	color = document.getElementById('preview_hex_color').value;
	document.getElementById('color').value = color;
	preview_effect();
}
function change_strength(change)
{
	strength += change;
	strength = strength < 1 ? 0 : strength;
	
	document.getElementById('strength').value = strength;
	
	preview_effect();
}
function change_direction(change)
{
	direction += parseInt(document.getElementById('change_direction_number').value) * change;
	direction = direction % 360;
	
	document.getElementById('direction').value = direction;
	
	preview_effect();
}
function change_text_shown()
{
	show_text = document.getElementById('show_text').checked;
	preview_effect();
}
function change_offset(x,y)
{
	offset_x += x;
	offset_y += y;
	
	document.getElementById('x_offset').value = offset_x;
	document.getElementById('y_offset').value = offset_y;
	
	preview_effect();
}
function change_dropshadow_background()
{
	show_drop_bg = !document.getElementById('drop_background').checked;
	preview_effect();
}
function preview_effect()
{
	if(effect == 'bold')
	{
		document.getElementById('preview').innerHTML = '<b>'+short_name+'</b>';
	}
	else if(effect == 'italics')
	{
		document.getElementById('preview').innerHTML = '<i>'+short_name+'</i>';
	}
	else if(effect == 'color')
	{
		document.getElementById('preview').style.color = color;
	}
	else if(effect == 'background')
	{
		document.getElementById('preview').style.backgroundColor = color;
	}
	else if(effect == 'blur')
	{
		document.getElementById('preview').style.filter = 'blur(add='+show_text+', direction='+direction+', strength='+strength+')';
	}
	else if(effect == 'flipv')
	{
		document.getElementById('preview').style.filter = 'flipv';
	}
	else if(effect == 'fliph')
	{
		document.getElementById('preview').style.filter = 'fliph';
	}
	else if(effect == 'wave')
	{
		document.getElementById('preview').style.filter = 'wave(strength='+strength+')';
	}
	else if(effect == 'xray')
	{
		document.getElementById('preview').style.filter = 'xray';
	}
	else if(effect == 'invert')
	{
		document.getElementById('preview').style.filter = 'invert';
	}
	else if(effect == 'dropshadow')
	{
		document.getElementById('preview').style.filter = 'dropshadow(color='+color+', offx='+offset_x+', offy='+offset_y+', Positive='+show_drop_bg+')';
	}
	else if(effect == 'shadow')
	{
		document.getElementById('preview').style.filter = 'shadow(color='+color+', direction='+direction+')';
	}
	else if(effect == 'glow')
	{
		document.getElementById('preview').style.filter = 'glow(color='+color+', strength='+strength+')';
	}
}
</script>
<div class='formsubtitle'>{$this->ipsclass->lang['add_change_name_effect']}</div>
<form action='{$this->base_url}' method='post'>
{$hidden_fields}
	<table class='ipbtable' cellspacing='0' cellpadding='0'>
{$pick_color}{$strength}{$direction}{$show_text}{$offset}{$background}
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['preview']}</b>
			</td>
			<td class='row2' align='left' width='10%'>
				<div id="post-member-0" class='popmenubutton-new-out'>
					<span class="normalname">{$effects[0]}<img src='{$this->ipsclass->vars['img_url']}/folder_profile_portal/user-online.png' alt='' border='0' /><a href='{$this->ipsclass->base_url}showuser={$this->ipsclass->member['id']}'>{$this->ipsclass->member['members_display_name_short']}</a>{$effects[1]}</span>
				</div>
				<!-- member menu -->
				<div class='popupmenu-new' id='post-member-0_menu' style='display:none;width:230px'>
					<div class='popupmenu-item-last'>
						<div class='popupmenu-item'><strong>{$this->ipsclass->member['members_display_name']}</strong></div>
					</div>
				</div>
				<!-- member menu -->
				<script type="text/javascript">
					ipsmenu.register( "post-member-0", '', 'popmenubutton-new', 'popmenubutton-new-out' );
				</script>
			</td>
		</tr>
		<tr>
			<td class='darkrow1' align='center' colspan='2'>
				<input type='submit' name='item_used' value='{$this->ipsclass->lang['apply_name_effect']}' class='forminput' />
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
preview_effect();
</script>
EOF;
		}
		else
		{
			unset($effect[$this->item_config['effect']]);
			
			$effects = $this->parse_effect($effect);
			
			return <<<EOF
<div class='formsubtitle'>{$this->ipsclass->lang['remove_change_name_effect']}</div>
<form action='{$this->base_url}' method='post'>
{$hidden_fields}
	<table class='ipbtable' cellspacing='0' cellpadding='0'>
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['preview']}</b>
			</td>
			<td class='row2' align='left' width='10%'>
				<div id="post-member-0" class='popmenubutton-new-out'>
					<span class="normalname">{$effects[0]}<div id='preview' style='width:100%'><img src='{$this->ipsclass->vars['img_url']}/folder_profile_portal/user-online.png' alt='' border='0' /><a href='{$this->ipsclass->base_url}showuser={$this->ipsclass->member['id']}'>{$this->ipsclass->member['members_display_name_short']}</a></div>{$effects[1]}</span>
				</div>
				<!-- member menu -->
				<div class='popupmenu-new' id='post-member-0_menu' style='display:none;width:230px'>
					<div class='popupmenu-item-last'>
						<div class='popupmenu-item'><strong>{$this->ipsclass->member['members_display_name']}</strong></div>
					</div>
				</div>
				<!-- member menu -->
				<script type="text/javascript">
					ipsmenu.register( "post-member-0", '', 'popmenubutton-new', 'popmenubutton-new-out' );
				</script>
			</td>
		</tr>
		<tr>
			<td class='darkrow1' align='center' colspan='2'>
				<input type='submit' name='item_used' value='{$this->ipsclass->lang['apply_name_effect']}' class='forminput' />
			</td>
		</tr>
	</table>
</form>
EOF;
		}
	}
	
	function input_done()
	{
		return isset($this->ipsclass->input['item_used']);
	}
	
	function public_use_item($inventory_ids = array()) 
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$effect = $this->ipsclass->member['multiple_effect'] ? unserialize($this->ipsclass->member['multiple_effect']) : array();
		$effect = is_array($effect) ? $effect : array();
		
		unset($effect[$this->item_config['effect']]);
		if($this->item_config['add_remove'] == 'add')
		{
			$effect[$this->item_config['effect']] = array();
			if(!in_array($this->item_config['effect'],array('bold','italics','blur','flipv','fliph','wave','xray','invert')))
			{
				$effect[$this->item_config['effect']]['color'] = $this->ipsclass->input['color'];
			}
			if(in_array($this->item_config['effect'],array('blur','wave','glow')))
			{
				$effect[$this->item_config['effect']]['strength'] = max(intval($this->ipsclass->input['strength']),0);
			}
			if(in_array($this->item_config['effect'],array('blur','shadow')))
			{
				$effect[$this->item_config['effect']]['direction'] = intval($this->ipsclass->input['direction']) % 360;
			}
			if($this->item_config['effect'] == 'blur')
			{
				$effect[$this->item_config['effect']]['show_text'] = isset($this->ipsclass->input['show_text']) && $this->ipsclass->input['show_text'];
			}
			if($this->item_config['effect'] == 'dropshadow')
			{
				$effect[$this->item_config['effect']]['offx'] = intval($this->ipsclass->input['x_offset']);
				$effect[$this->item_config['effect']]['offy'] = intval($this->ipsclass->input['y_offset']);
				$effect[$this->item_config['effect']]['drop_background'] = !isset($this->ipsclass->input['drop_background']) || !$this->ipsclass->input['drop_background'];
			}
		}
		
		$this->ipsclass->DB->do_update('members',array(
															'multiple_effect' => serialize($effect),
					),"id=".$this->ipsclass->member['id']);
		
		$this->delete_items($inventory_ids);
		
		$inv_id = reset($inventory_ids);
		$this->_write_log($inv_id, "Applied multiple name effect on {$this->ipsclass->member['members_display_name']}");
		
		$this->ipsclass->market_class->redirect('name_effect_applied');
	}
	
	function parse_effect($effects = array())
	{
		$prefix = $suffix = "";
		foreach($effects as $type => $effect)
		{
			if($type == 'bold')
			{
				$prefix .= "<b>";
				$suffix = "</b>".$suffix;
			}
			elseif($type == 'italics')
			{
				$prefix .= "<i>";
				$suffix = "</i>".$suffix;
			}
			elseif($type == 'color')
			{
				$prefix .= "<span style=\"color:{$effect['color']}\">";
				$suffix = "</span>".$suffix;
			}
			elseif($type == 'background')
			{
				$prefix .= "<span style=\"background-color:{$effect['color']}\">";
				$suffix = "</span>".$suffix;
			}
			elseif($type == 'dropshadow')
			{
				$prefix .= "<div style=\"width:100%; filter:dropshadow(color='{$effect['color']}', offx={$effect['offx']}, offy={$effect['offy']}, Positive=".($effect['drop_background'] ? 'true' : 'false').")\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'shadow')
			{
				$prefix .= "<div style=\"width:100%; filter:shadow(color='{$effect['color']}', direction={$effect['direction']})\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'glow')
			{
				$prefix .= "<div style=\"width:100%; filter:glow(color='{$effect['color']}', strength={$effect['strength']})\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'blur')
			{
				$prefix .= "<div style=\"width:100%; filter:blur(add=".($effect['show_text'] ? 'true' : 'false').", direction={$effect['direction']}, strength={$effect['strength']})\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'flipv')
			{
				$prefix .= "<div style=\"width:100%; filter:flipv\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'fliph')
			{
				$prefix .= "<div style=\"width:100%; filter:fliph\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'wave')
			{
				$prefix .= "<div style=\"width:100%; filter:wave(strength={$effect['strength']})\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'xray')
			{
				$prefix .= "<div style=\"width:100%; filter:xray\">";
				$suffix = "</div>".$suffix;
			}
			elseif($type == 'invert')
			{
				$prefix .= "<div style=\"width:100%; filter:invert\">";
				$suffix = "</div>".$suffix;
			}
		}
		
		return array($prefix,$suffix);
	}
}
?>